$(function(){
    // -----------regist----------------
    $("#regist_button").click(function(){
        //alert("1111111111111")
        $("#warning_1").hide()
        $("#warning_2").hide()
        $("#warning_3").hide()
        //校验数据
        var name = $("#regist_username").val().trim();
        var nick = $("#nickname").val().trim();
        var password = $("#regist_password").val().trim();
        var final_password = $("#final_password").val().trim();
        var ok = true;
        if(name ==""){
            ok = false;
            $("#warning_1 span").html("用户名为空")
            $("#warning_1").show()
        }

        if(password ==""){
            ok = false;
            $("#warning_2 span").html("密码为空")
            $("#warning_2").show()
        }else{
            if(password.length < 6){
                ok = false;
                $("#warning_2 span").html("密码需要6位以上")
                $("#warning_2").show()
            }
        }
        if(final_password != password){
            ok = false;
            $("#warning_3 span").html("与密码不一致")
            $("#warning_3").show()
        }
        //发送ajax请求
        if(ok){
            $.ajax({
                url:"http://localhost:80/user/regist.do",
                type:"post",
                dataType:"json",
                data:{"name":name,"password":password,"nick":nick},
                success:function(result){
                    //status 0 1
                    if(result.status == 0){
                        alert(result.msg)
                        $("#back").click()//跳转到登录页
                    }else if(result.status == 1){//用户名被占用
                        $("#warning_1 span").html(result.msg)
                        $("#warning_1").show()
                    }
                },
                error:function () {
                    alert("注册失败，稍后重试")
                }
            })
        }


    })
})